package Gr

import (
	"fmt"
	"db2s/ETL"
	"db2s/global"
	"db2s/parDef"
	"db2s/ref"
)

func (pm PartitionMe) Set(parameter string, value any) (err error) {
	return ref.UpdateStructJsonValue(pm, parameter, value)
}
func (pm PartitionMe) Result(object string) global.Return {
	switch object {
	default:
		return global.Return{}
	}
}
func (pm PartitionMe) PartType(parameter parDef.Parameter) (result global.Return, err error) {
	var event = "[PartType]"
	var execSql []string
	execSql = append(execSql, fmt.Sprintf("select "+
		"distinct concat(PARTITION_METHOD,',',IFNULL(SUBPARTITION_METHOD,''))  "+
		"from "+
		"information_schema.partitions "+
		"where "+
		"table_schema='%v' "+
		"and table_name='%v' "+
		"and PARTITION_METHOD is not null",
		parameter.Object.Schema, parameter.Object.Table))
	if result, err = forExecQuerySql(event, parameter, ETL.String, execSql); err != nil || result.Result == nil {
		return
	}
	return
}
func (pm PartitionMe) PartSum(parameter parDef.Parameter) (result global.Return, err error) {
	var event = "[PartSum]"
	var execSql []string

	execSql = append(execSql, fmt.Sprintf("select "+
		"count(1) AS `sum` "+
		"FROM "+
		"INFORMATION_SCHEMA.PARTITIONS "+
		"WHERE "+
		"TABLE_SCHEMA = '%v' "+
		"AND TABLE_NAME = '%v' "+
		"and PARTITION_METHOD is not null",
		parameter.Object.Schema, parameter.Object.Table))
	if result, err = forExecQuerySql(event, parameter, ETL.String, execSql); err != nil || result.Result == nil {
		return
	}
	if result.Result, err = stringAnyToInt64(result.Result); err != nil {
		return
	}
	return
}
func (pm PartitionMe) PartMeta(parameter parDef.Parameter) (result global.Return, err error) {
	return
}
